<?php

use Illuminate\Database\Seeder;

class MrpChangeLogTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        $users = DB::table('users')->pluck('id')->toArray();
        $mrpConfig = DB::table('mrp_config')->pluck('num')->toArray();
        $datas = [];

        $beginLastweek = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
        $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));

        foreach (range(100, 200) as $index)
        {
            $datas[] = [
                'uid'  => $users[array_rand($users, 1)],
                'change_num' => $mrpConfig[array_rand($mrpConfig, 1)],
                'created_at'  => rand($beginLastweek, $endLastweek),
            ];
        }
        DB::table('mrp_change_log')->insert($datas);
    }
}
